package letsjava.socket;

import java.io.*;
import java.net.*;
import java.util.*;

public class SocketServer {
	public static void main(String[] args) throws IOException{
		ServerSocket serverSocket = new ServerSocket(8199);
		
		Socket incoming = serverSocket.accept();
		
		InputStream inStream = incoming.getInputStream();
		OutputStream outStream = incoming.getOutputStream();
		
		Scanner in = new Scanner(inStream);
		
		//PrintWriter out = new PrintWriter(outStream,true);
		PrintStream out = new PrintStream(outStream,true/*auto flush*/);
		
		out.println("Welcome to Socket Server, type BYE to exit");
		
		boolean done = false;
		while(!done && in.hasNextLine()){
			String line = in.nextLine();
			out.println("Echo :" + line);
			if(line.trim().equals("BYE")){
				done = true;
			}
		}
		
		
		out.println("BYE! ");
		
		
		
	}
}
